package com.example.a10928.weifriend.ui.home.menu

import android.annotation.SuppressLint
import android.databinding.ViewDataBinding
import android.graphics.drawable.Drawable
import android.support.v4.content.ContextCompat
import android.support.v4.content.ContextCompat.getDrawable
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.example.a10928.weifriend.App.app
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.R.drawable.*
import com.example.a10928.weifriend.adapter.CarStoreAdapter
import com.example.a10928.weifriend.databinding.ActivityCarStoreBinding
import com.example.a10928.weifriend.http.api.base.CarMallBean
import com.example.a10928.weifriend.ui.DatabindingBaseActivity
import com.example.a10928.weifriend.util.RxUtil
import kotlinx.android.synthetic.main.activity_car_store.*

class CarStoreActivity : DatabindingBaseActivity() {
    var data: MutableList<CarMallBean.CarMallDataBean> = mutableListOf()
    lateinit var mBinding: ActivityCarStoreBinding
    override fun bindingInitData() {
    }


    override fun bindingInitView(viewDataBinding: ViewDataBinding?) {
        setTitleText(ThemeEnum.Back_Default, "汽车商城")
        mBinding = viewDataBinding as ActivityCarStoreBinding

        mBinding.carStoreRv.layoutManager = GridLayoutManager(this, 3) as RecyclerView.LayoutManager?
        getData()
    }

    override fun bindingGetContentView(): Int {
        return R.layout.activity_car_store
    }

    @SuppressLint("CheckResult")
    private fun getData() {
        app().bpService.carMall.compose(RxUtil.io2mainLoad(this))
                .subscribe(
                        { r ->
                            data = r.data.car_mall
                            mBinding.carStoreRv.adapter = CarStoreAdapter(R.layout.item_car_store, data)
                        },
                        { RxUtil::errorException }
                )
    }


}